/*--------------------------------------------------------------------------
	@class common.patterns.observer.AbstractObservable
	@author Eduardo Echeverria
	@version 1.0 April 5, 2005
	@description
  --------------------------------------------------------------------------
*/
sci.Require('sci.quadrant.QuadrantViewModel');
sci.Provide('sci.quadrant.NavigatorController');

//-- Public Constructor -----------------------------------------------------
sci.quadrant.NavigatorController = function (view, viewModel) {
    if (!view)
        throw 'sci.quadrant.NavigatorController :: A view is required';

    this.View = view;
    this.ViewModel = null;

    this.Image = document.createElement("img");
    this.View.appendChild(this.Image);
    this.ImageFolder = this.View.getAttribute('data-image-folder');

    this.Finder = document.createElement("div");
    this.Finder.style.border = "solid";
    this.Finder.style.borderColor = "#F00";
    this.Finder.style.position = "absolute";
    this.Finder.style.width = "15px";
    this.Finder.style.height = "10px";
    this.Finder.style.left = "0px";
    this.Finder.style.top = "0px";
    this.Finder.style.borderWidth = "1px";
    this.View.appendChild(this.Finder);

    this.FinderWidth = 10;
    this.FinderHeight = 10;

    if (viewModel)
        this.SetViewModel(viewModel);
};

///*--------------------------------------------------------------------------
//	@method removeObserver
//	@param 
//	@description 
//  --------------------------------------------------------------------------
//*/
sci.quadrant.NavigatorController.prototype.GetView = function () {
    return this.View;
};

sci.quadrant.NavigatorController.prototype.GetViewModel = function () {
    return this.ViewModel;
}

sci.quadrant.NavigatorController.prototype.SetViewModel = function (viewModel) {
    if (this.ViewModel) {
        this.ViewModel.RemoveObserver('ContentUpdate', this);
        this.ViewModel.RemoveObserver('LocationChanged', this);
        //this.ViewModel.RemoveObserver('SizeChange', this);
    }

    this.ViewModel = viewModel;

    if (this.ViewModel) {
        this.ViewModel.AddObserver('ContentUpdate', this, 'ViewModel_ContentUpdate');
        this.ViewModel.AddObserver('LocationChange', this, 'ViewModel_LocationChange');
        //this.ViewModel.AddObserver('SizeChange', this, 'ViewModel_SizeChange');

        this.InitializeView();
    }
};

sci.quadrant.NavigatorController.prototype.InitializeView = function () {
    this.Image.src = this.ImageFolder + this.ViewModel.GetThumbnail();
};

sci.quadrant.NavigatorController.prototype.ResizeFinder = function (w, h) {
    this.Finder.style.width = w + "px";
    this.Finder.style.height = h + "px";

    this.FinderWidth = w;
    this.FinderHeight = h;
};

sci.quadrant.NavigatorController.prototype.ViewModel_LocationChange = function (e) {
    this.Finder.style.left = (this.ViewModel.GetThumbnailWidth() * this.ViewModel.GetX() / this.ViewModel.GetWidth()) + "px";
    this.Finder.style.top = (this.ViewModel.GetThumbnailHeight() * this.ViewModel.GetY() / this.ViewModel.GetHeight()) + "px";
};

//sci.quadrant.NavigatorController.prototype.ViewModel_SizeChange = function (e) {
//    //this.ResizeFinder(Math.floor(this.ViewModel.GetThumbnailWidth() * mapView.clientWidth / vis.getWidth()), Math.floor(vis.getHeightT() * mapView.clientHeight / vis.getHeight()));
//};

sci.quadrant.NavigatorController.prototype.ViewModel_ContentUpdate = function (e) {
    this.InitializeView();
};

sci.quadrant.NavigatorController.prototype.toString = function () {
    return "[Object:NavigatorController]";
}

sci.Ready('sci.quadrant.NavigatorController');